<template>
  <div style="padding: 20px">
    <div class="headerBoxList">
      <svg width="24" height="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
        <path
          d="M42 7H6C4.89543 7 4 7.89543 4 9V37C4 38.1046 4.89543 39 6 39H42C43.1046 39 44 38.1046 44 37V9C44 7.89543 43.1046 7 42 7Z"
          fill="none" stroke="#333" stroke-width="4" stroke-linejoin="round" />
        <path d="M12 19H14" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" />
        <path d="M21 19H23" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" />
        <path d="M29 19H36" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" />
        <path d="M12 28H36" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" />
      </svg>
      <span style="margin-left: 10px">输入法</span>
    </div>
    <div class="contentBoxYY" style="">
      <el-collapse v-model="activeName" accordion>
        <el-collapse-item v-for="(item, index) in listData" :key="index"
          :title="'🚩 ' + item.titleKey + ` （${item.content.length}行）`" :name="index">
          <div style="background: #282828;color: rgb(101, 177, 235);padding-left:20px;" v-for="(data, j) in item.content"
            :key="j">
            {{ data }}
          </div>
        </el-collapse-item>
      </el-collapse>
    </div>
  </div>
</template>
  
<script>
import { getRxTmpPathApi } from '@/api/phoneInfo/index'
export default {
  name: "inputtingMethod",
  props: ['sendData'],
  data() {
    return {
      activeName: 0,
      listData: []
    };
  },
  mounted() {
  },
  watch: {
    '$store.state.account.basePhone': function () {
      this.initFunction();
    }
  },
  created() {
    this.initFunction();
  },
  methods: {
    initFunction() {

      let node = this.sendData;
      let dataJson = {
        "proof_num": node.proof_num,
        "rxTmpPath": node.href,
      }
      getRxTmpPathApi(dataJson).then(res => {
        const stringData = res.data;

        const delimiters = [
          "Current Input Method Manager state:",
          "InputMethod #0:",
          "mStartInputHistory:",
          "mSoftInputShowHideHistory:",
        ];

        const dataArray = [];
        let currentData = "";

        for (let i = 0; i < delimiters.length; i++) {
          const delimiter = delimiters[i];
          const startIndex = stringData.indexOf(delimiter);
          const endIndex = i < delimiters.length - 1 ? stringData.indexOf(delimiters[i + 1]) : stringData.length;

          if (startIndex !== -1 && endIndex !== -1) {
            const data = stringData.slice(startIndex, endIndex).trim();
            dataArray.push(data);
          }
        }
        let arr = [];
        // 格式化字符串数组为json数据
        for (let index = 0; index < dataArray.length; index++) {
          const element = dataArray[index];
          const originalString = element;
          const delimiter = "\n";

          const delimiterIndex = originalString.indexOf(delimiter);

          if (delimiterIndex !== -1) {
            const firstPart = originalString.substring(0, delimiterIndex).trim();
            const secondPart = originalString
              .substring(delimiterIndex + 1)
              .trim();
            let item = {
              titleKey: firstPart,
              content: secondPart.split("\n"),
            };
            arr.push(item);
          } else {
            console.log("Delimiter not found in the string.");
          }

          // arr.push(item)
        }
        this.listData = arr;
      })


    },
  },
};
</script>
  
<style scoped>
.headerBoxList {
  width: 100%;
  height: 50px;
  border-bottom: 1px solid #d2d2d2;
  display: flex;
  align-items: center;
  font-size: 18px;
  font-weight: bold;
}

.contentBoxYY {
  width: 95%;
  margin: 0 auto;
  overflow: hidden;
  height: 86vh;
  overflow-y: auto;
  overflow-x: hidden;
  overflow-wrap: break-word
}

@media screen and (min-width: 2360px) {
  .contentBoxYY {
    width: 95%;
    margin: 0 auto;
    overflow: hidden;
    height: 81vh;
    overflow-y: auto;
    overflow-x: hidden;
    overflow-wrap: break-word
  }
}

@media screen and (min-width: 2561px) {
  .contentBoxYY {
    width: 95%;
    margin: 0 auto;
    overflow: hidden;
    height: 67vh;
    overflow-y: auto;
    overflow-x: hidden;
    overflow-wrap: break-word
  }
}</style>